//
//  JPickerV+AreaInfo.m
//  jhf
//
//  Created by Mac on 2020/6/15.
//  Copyright © 2020 计海峰. All rights reserved.
//

#import "JPickerV+AreaInfo.h"
#import "ProvinceModel.h"

@implementation JPickerV (AreaInfo)

- (void)showWithAreaInfo:(BlockValue)block; {
    NSMutableArray *dataArray = [NSMutableArray array];
    [JLOCAL_FILE_JSON_ID(@"city.json") enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        ProvinceModel *province = [ProvinceModel mj_objectWithKeyValues:obj];
        JPickerModel *provincePicker = [JPickerModel initWithName:province.province identify:province.provinceId];
        
        NSMutableArray *cityArray = [NSMutableArray array];
        [province.citys enumerateObjectsUsingBlock:^(CitysModel * _Nonnull city, NSUInteger idx, BOOL * _Nonnull stop) {
            JPickerModel *cityPicker = [JPickerModel initWithName:city.city identify:city.cityId];

            NSMutableArray *areaArray = [NSMutableArray array];
            [city.areas enumerateObjectsUsingBlock:^(AreasModel * _Nonnull area, NSUInteger idx, BOOL * _Nonnull stop) {
                JPickerModel *areaPicker = [JPickerModel initWithName:area.area identify:area.areaId];
                [areaArray addObject:areaPicker];
            }];
            cityPicker.arrays  = areaArray;
            
            [cityArray addObject:cityPicker];
            
        }];
        provincePicker.arrays = cityArray;
        [dataArray addObject:provincePicker];
    }];
    
    [self showWithArray:dataArray select:block];
}

@end
